import aircv as ac
from cv2.typing import map_int_and_double

from common.tools import get_project_path, build_path


class FindImg:
    def img_read(self, img_path):
        # ac库读取图片后返回这个图片对象的内容
        return ac.imread(img_path)

    # 获取图片的相似度
    def get_confidence(self, source_path, search_path):
        img_src = self.img_read(source_path)
        img_sch = self.img_read(search_path)

        result = ac.find_template(img_src, img_sch)
        print(result)
        return result['confidence']


if __name__ == '__main__':
    source_path = get_project_path() + build_path('img', 'source_img', 'dangdang_home_book_icon.png',
                                                  add_sep_before=True)
    search_path = get_project_path() + build_path("img", "assert_img", "dangdang_home_book_icon2.png",
                                                  add_sep_before=True)
    FindImg().get_confidence(source_path, search_path)

